package chapter08

/**
  * create by undeRdoG on  2021-06-06  13:29
  * 凡心所向，素履以往，生如逆旅，一苇以航。
  */
object Test02_MatchTypes {

  def main(args: Array[String]): Unit = {
    // 匹配常量
    def describeConst(x: Any): String = {
      x match {
        case 1 => "Int one"
        case "hello" => "String hello"
        case true => "Boolean true"
        case _ => "Exception"
      }
    }

    println(describeConst("hello"))


    println("=================================================================================")
    // 类型匹配
    def describeType(x: Any): String = {
      x match {
        case i: Int => "Int"
        case x: String => "String"
        case x: Boolean => "Boolean"
        case x: List[Any] => "List"

          // 相当于定义 case _   但此种方式可以拿到传入的参数
        case a => "unknow type" + a.getClass
      }
    }


    println(describeType(23.43F))

    

  }
}
